home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / zoo tutorial / module 7- switching compositors / source / zoopane.java < prev   
Encoding:
Java Source  |  2000-06-23  |  6.7 KB  |  212 lines

  1. import java.awt.AWTEventMulticaster;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import java.awt.event.MouseListener;
  5. import java.awt.event.MouseEvent;
  6. import java.awt.Point;
  7.  
  8. import quicktime.QTException;
  9. import quicktime.app.anim.Compositor;
  10. import quicktime.app.anim.TwoDSprite;
  11.  
  12. import quicktime.app.event.QTMouseTargetController;
  13. import quicktime.app.event.MouseButtonListener;
  14. import quicktime.app.event.MouseTargetAdapter;
  15. import quicktime.app.event.QTMouseEvent;
  16. import quicktime.qd.QDColor;
  17. import quicktime.qd.QDConstants;
  18. import quicktime.std.image.GraphicsMode;
  19.  
  20. /**
  21.  * The pane that specifies common behavior for all of the panes in the zoo project
  22.  *
  23.  * @author Levi Brown
  24.  * @author Michael Hopkins
  25.  * @author Apple Computer, Inc.
  26.  * @version 1.0 10/21/1999
  27.  *
  28.  * Copyright:     © Copyright 1999 Apple Computer, Inc. All rights reserved.
  29.  *    
  30.  * Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  31.  *                ("Apple") in consideration of your agreement to the following terms, and your
  32.  *                use, installation, modification or redistribution of this Apple software
  33.  *                constitutes acceptance of these terms.  If you do not agree with these terms,
  34.  *                please do not use, install, modify or redistribute this Apple software.
  35.  *
  36.  *                In consideration of your agreement to abide by the following terms, and subject
  37.  *                to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  38.  *                copyrights in this original Apple software (the "Apple Software"), to use,
  39.  *                reproduce, modify and redistribute the Apple Software, with or without
  40.  *                modifications, in source and/or binary forms; provided that if you redistribute
  41.  *                the Apple Software in its entirety and without modifications, you must retain
  42.  *                this notice and the following text and disclaimers in all such redistributions of
  43.  *                the Apple Software.  Neither the name, trademarks, service marks or logos of
  44.  *                Apple Computer, Inc. may be used to endorse or promote products derived from the
  45.  *                Apple Software without specific prior written permission from Apple.  Except as
  46.  *                expressly stated in this notice, no other rights or licenses, express or implied,
  47.  *                are granted by Apple herein, including but not limited to any patent rights that
  48.  *                may be infringed by your derivative works or by other works in which the Apple
  49.  *                Software may be incorporated.
  50.  *
  51.  *                The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  52.  *                WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  53.  *                WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  54.  *                PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  55.  *                COMBINATION WITH YOUR PRODUCTS.
  56.  *
  57.  *                IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  58.  *                CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  59.  *                GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  60.  *                ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  61.  *                OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  62.  *                (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  63.  *                ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  64.  * 
  65.  */
  66. public abstract class ZooPane
  67. {
  68.     /**
  69.      *
  70.      */
  71.     public Compositor getCompositor()
  72.     {
  73.         return compositor;
  74.     }
  75.  
  76.     /**
  77.      * Called to do any setup after being set as the client of the QTCanvas.
  78.      * May be used to start effects running, movies playing, etc.
  79.      */
  80.     abstract public void start();
  81.  
  82.     /**
  83.      * Called to do clean up after being removed as the client of the QTCanvas.
  84.      * Should be used to stop effects running, movies playing, etc.
  85.      */
  86.     abstract public void stop();
  87.  
  88.     /**
  89.      * Sets the command name of the action event fired by this button.
  90.      * @param command The name of the action event command fired by this button
  91.      */
  92.     protected void setActionCommand( String command )
  93.     {
  94.         actionCommand = command;
  95.     }
  96.  
  97.     /**
  98.      * Fire an action event to the listeners.
  99.      */
  100.     protected void fireActionEvent()
  101.     {
  102.         if (actionListener != null)
  103.             actionListener.actionPerformed( new ActionEvent( this, ActionEvent.ACTION_PERFORMED, actionCommand ));
  104.     }
  105.  
  106.     /**
  107.      * Responds to mouse events from the animal regions and various buttons
  108.      */
  109.     public class PaneMouseListener extends MouseTargetAdapter implements MouseButtonListener
  110.     {
  111.         public PaneMouseListener( QDColor normalBlend, QDColor rollOverBlend, QDColor clickedBlend )
  112.         { 
  113.             normalGM   = new GraphicsMode( QDConstants.blend, normalBlend   );
  114.             rollOverGM = new GraphicsMode( QDConstants.blend, rollOverBlend );
  115.             clickedGM  = new GraphicsMode( QDConstants.blend, clickedBlend  );
  116.         }
  117.         
  118.         public void mouseTargetEntered( QTMouseEvent e )
  119.         {
  120.             isMouseInside = true;
  121.             try
  122.             {
  123.                 if ( e.getTarget() instanceof TwoDSprite )
  124.                 {
  125.                     TwoDSprite sp = (TwoDSprite) e.getTarget();
  126.                     if (isMousePressed)
  127.                         sp.setGraphicsMode( clickedGM );
  128.                     else
  129.                         sp.setGraphicsMode( rollOverGM );
  130.                 }
  131.             }
  132.             catch (QTException exc)
  133.             {    
  134.                 exc.printStackTrace();
  135.             }
  136.         }
  137.         
  138.         public void mouseTargetExited( QTMouseEvent e )
  139.         {
  140.             isMouseInside = false;
  141.             try
  142.             {
  143.                 if ( e.getTarget() instanceof TwoDSprite )
  144.                 {
  145.                     TwoDSprite sp = (TwoDSprite) e.getTarget();
  146.                     sp.setGraphicsMode( normalGM );
  147.                 }
  148.             }
  149.             catch (QTException exc)
  150.             {    
  151.                 exc.printStackTrace();
  152.             }
  153.         }
  154.  
  155.         public void mouseClicked( QTMouseEvent e ) {}
  156.         
  157.         public void mousePressed( QTMouseEvent e )
  158.         {
  159.             isMousePressed = true;
  160.             try
  161.             {
  162.                 if ( e.getTarget() instanceof TwoDSprite )
  163.                 {
  164.                     TwoDSprite sp = (TwoDSprite) e.getTarget();
  165.                     sp.setGraphicsMode( clickedGM );
  166.                 }
  167.             }
  168.             catch (QTException exc)
  169.             {    
  170.                 exc.printStackTrace();
  171.             }        
  172.         }
  173.         
  174.         public void mouseReleased( QTMouseEvent e )
  175.         {
  176.             isMousePressed = false;
  177.             try
  178.             {
  179.                 if ( e.getTarget() instanceof TwoDSprite )
  180.                 {
  181.                     TwoDSprite sp = (TwoDSprite) e.getTarget();
  182.                     
  183.                     if (isMouseInside)
  184.                     {
  185.                         sp.setGraphicsMode( rollOverGM );
  186.                         setActionCommand("Button" + ";" + e.getX() + ";" + e.getY());
  187.                         fireActionEvent();
  188.                     }
  189.                     else
  190.                         sp.setGraphicsMode( normalGM );
  191.                 }
  192.             }
  193.             catch (QTException exc)
  194.             {    
  195.                 exc.printStackTrace();
  196.             }
  197.         }
  198.         GraphicsMode rollOverGM = new GraphicsMode( QDConstants.blend, QDColor.darkGray );
  199.         GraphicsMode clickedGM = new GraphicsMode( QDConstants.blend, QDColor.lightGray );
  200.         GraphicsMode normalGM;
  201.     }
  202.     
  203.     protected String actionCommand;
  204.     protected ActionListener actionListener = null;
  205.  
  206.     protected QTMouseTargetController ctr;    
  207.     protected Compositor compositor;
  208.  
  209.     protected boolean isMouseInside;
  210.     protected boolean isMousePressed;
  211. }
  212.